package com.kuangstudy.thread.syn;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author Losca
 * @date 2021/7/20 22:49
 * juc并发编程
 */
public class Demo2 {
    public static void main(String[] args) {
        /*CopyOnWriteArrayList 线程安全*/
        CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 10000; i++) {
            new Thread(()->{
                list.add(Thread.currentThread().getName());
            }).start();
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(list.size());//10000
    }
}
